from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-02-11 14:09:43.716420
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 11, Feb, 2021
Time: 14:09:47
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.0880
Nobs: 199.000 HQIC: -46.9747
Log likelihood: 2282.64 FPE: 2.17618e-21
AIC: -47.5775 Det(Omega_mle): 1.39977e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.469314 0.140970 3.329 0.001
L1.Burgenland 0.082646 0.072519 1.140 0.254
L1.Kärnten -0.217454 0.061255 -3.550 0.000
L1.Niederösterreich 0.132213 0.168809 0.783 0.434
L1.Oberösterreich 0.241883 0.148060 1.634 0.102
L1.Salzburg 0.201542 0.078070 2.582 0.010
L1.Steiermark 0.101132 0.105176 0.962 0.336
L1.Tirol 0.147794 0.070418 2.099 0.036
L1.Vorarlberg -0.002876 0.064882 -0.044 0.965
L1.Wien -0.142289 0.141933 -1.003 0.316
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.491341 0.170454 2.883 0.004
L1.Burgenland 0.016583 0.087686 0.189 0.850
L1.Kärnten 0.364897 0.074066 4.927 0.000
L1.Niederösterreich 0.123570 0.204115 0.605 0.545
L1.Oberösterreich -0.136134 0.179027 -0.760 0.447
L1.Salzburg 0.195067 0.094398 2.066 0.039
L1.Steiermark 0.214915 0.127174 1.690 0.091
L1.Tirol 0.140800 0.085146 1.654 0.098
L1.Vorarlberg 0.176370 0.078452 2.248 0.025
L1.Wien -0.575973 0.171618 -3.356 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.310191 0.062404 4.971 0.000
L1.Burgenland 0.105841 0.032102 3.297 0.001
L1.Kärnten -0.019493 0.027116 -0.719 0.472
L1.Niederösterreich 0.075068 0.074727 1.005 0.315
L1.Oberösterreich 0.287497 0.065542 4.386 0.000
L1.Salzburg 0.000456 0.034559 0.013 0.989
L1.Steiermark -0.017489 0.046559 -0.376 0.707
L1.Tirol 0.086631 0.031172 2.779 0.005
L1.Vorarlberg 0.109733 0.028722 3.821 0.000
L1.Wien 0.067465 0.062830 1.074 0.283
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.220859 0.070620 3.127 0.002
L1.Burgenland -0.010507 0.036329 -0.289 0.772
L1.Kärnten 0.023373 0.030686 0.762 0.446
L1.Niederösterreich 0.044052 0.084566 0.521 0.602
L1.Oberösterreich 0.380403 0.074172 5.129 0.000
L1.Salzburg 0.094369 0.039109 2.413 0.016
L1.Steiermark 0.182132 0.052689 3.457 0.001
L1.Tirol 0.040838 0.035276 1.158 0.247
L1.Vorarlberg 0.090187 0.032503 2.775 0.006
L1.Wien -0.067911 0.071102 -0.955 0.340
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.519555 0.141483 3.672 0.000
L1.Burgenland 0.056167 0.072782 0.772 0.440
L1.Kärnten 0.015089 0.061477 0.245 0.806
L1.Niederösterreich -0.041537 0.169422 -0.245 0.806
L1.Oberösterreich 0.150639 0.148598 1.014 0.311
L1.Salzburg 0.062284 0.078353 0.795 0.427
L1.Steiermark 0.129171 0.105558 1.224 0.221
L1.Tirol 0.212789 0.070674 3.011 0.003
L1.Vorarlberg 0.028848 0.065118 0.443 0.658
L1.Wien -0.123328 0.142448 -0.866 0.387
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.156848 0.099755 1.572 0.116
L1.Burgenland -0.019780 0.051317 -0.385 0.700
L1.Kärnten -0.012329 0.043346 -0.284 0.776
L1.Niederösterreich 0.112580 0.119454 0.942 0.346
L1.Oberösterreich 0.385351 0.104772 3.678 0.000
L1.Salzburg -0.015422 0.055244 -0.279 0.780
L1.Steiermark -0.024057 0.074426 -0.323 0.747
L1.Tirol 0.190529 0.049830 3.824 0.000
L1.Vorarlberg 0.035637 0.045913 0.776 0.438
L1.Wien 0.197916 0.100436 1.971 0.049
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.224315 0.128578 1.745 0.081
L1.Burgenland 0.062601 0.066144 0.946 0.344
L1.Kärnten -0.038576 0.055870 -0.690 0.490
L1.Niederösterreich -0.035417 0.153969 -0.230 0.818
L1.Oberösterreich -0.098103 0.135044 -0.726 0.468
L1.Salzburg 0.044281 0.071207 0.622 0.534
L1.Steiermark 0.394093 0.095930 4.108 0.000
L1.Tirol 0.490315 0.064227 7.634 0.000
L1.Vorarlberg 0.166845 0.059178 2.819 0.005
L1.Wien -0.209577 0.129455 -1.619 0.105
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.069834 0.153949 0.454 0.650
L1.Burgenland 0.028106 0.079195 0.355 0.723
L1.Kärnten -0.090126 0.066894 -1.347 0.178
L1.Niederösterreich 0.250637 0.184350 1.360 0.174
L1.Oberösterreich -0.010321 0.161691 -0.064 0.949
L1.Salzburg 0.237968 0.085257 2.791 0.005
L1.Steiermark 0.135332 0.114859 1.178 0.239
L1.Tirol 0.068224 0.076901 0.887 0.375
L1.Vorarlberg 0.042426 0.070856 0.599 0.549
L1.Wien 0.274132 0.155000 1.769 0.077
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.595230 0.081471 7.306 0.000
L1.Burgenland -0.029227 0.041911 -0.697 0.486
L1.Kärnten -0.004197 0.035401 -0.119 0.906
L1.Niederösterreich -0.038995 0.097559 -0.400 0.689
L1.Oberösterreich 0.296987 0.085568 3.471 0.001
L1.Salzburg 0.016158 0.045119 0.358 0.720
L1.Steiermark 0.011647 0.060784 0.192 0.848
L1.Tirol 0.080802 0.040696 1.985 0.047
L1.Vorarlberg 0.137581 0.037497 3.669 0.000
L1.Wien -0.061292 0.082027 -0.747 0.455
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.137796 0.036991 0.200785 0.256435 0.064991 0.097728 -0.056894 0.172355
Kärnten 0.137796 1.000000 0.012918 0.191887 0.165576 -0.111306 0.156160 0.019029 0.313573
Niederösterreich 0.036991 0.012918 1.000000 0.308859 0.082245 0.215825 0.125477 0.053358 0.365112
Oberösterreich 0.200785 0.191887 0.308859 1.000000 0.296928 0.295774 0.108077 0.080441 0.131511
Salzburg 0.256435 0.165576 0.082245 0.296928 1.000000 0.151940 0.061959 0.089001 -0.011926
Steiermark 0.064991 -0.111306 0.215825 0.295774 0.151940 1.000000 0.108644 0.094493 -0.093528
Tirol 0.097728 0.156160 0.125477 0.108077 0.061959 0.108644 1.000000 0.163616 0.151000
Vorarlberg -0.056894 0.019029 0.053358 0.080441 0.089001 0.094493 0.163616 1.000000 0.069923
Wien 0.172355 0.313573 0.365112 0.131511 -0.011926 -0.093528 0.151000 0.069923 1.000000